package com.linkage.event.controller;

import cn.hutool.core.util.StrUtil;
import com.linkage.common.base.RequestInfo;
import com.linkage.common.base.ResponseInfo;
import com.linkage.event.pojo.entity.FlagRemark;
import com.linkage.event.service.FlagRemarkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 红旗标识管理controller
 */
@RestController
@Slf4j
@RequestMapping("/event/remark")
public class FlagRemarkController {

    @Autowired
    private FlagRemarkService flagRemarkService;

    /**
     * 查询标识列表
     * @param requestInfo
     * @return
     */
    @PostMapping("/queryRemarkList")
    public ResponseInfo queryRemarkList(@RequestBody RequestInfo<FlagRemark> requestInfo){
        return ResponseInfo.success(flagRemarkService.queryList(requestInfo.getBuss()));
    }

    /**
     * 添加红旗标识
     * @param requestInfo
     * @return
     */
    @PostMapping("/addRemark")
    public ResponseInfo addRemark(@RequestBody RequestInfo<FlagRemark> requestInfo){
        FlagRemark remark = requestInfo.getBuss();
        if(StrUtil.hasEmpty(remark.getFlagName(),remark.getFlagDesc())){
            return ResponseInfo.error("标识名称或标识描述参数为空");
        }
        flagRemarkService.addFlagRemark(remark);
        return ResponseInfo.success("创建成功");
    }

    /**
     * 修改标识信息
     * @param requestInfo
     * @return
     */
    @PostMapping("/modifyRemark")
    public ResponseInfo modifyRemark(@RequestBody RequestInfo<FlagRemark> requestInfo){
        FlagRemark remark = requestInfo.getBuss();
        if(StrUtil.hasEmpty(remark.getId())){
            return ResponseInfo.error("标识id参数为空");
        }
        flagRemarkService.modifyFlagRemark(remark);
        return ResponseInfo.success("修改成功");
    }

    /**
     * 删除标识
     * @param requestInfo
     * @return
     */
    @PostMapping("/delRemark")
    public ResponseInfo delRemark(@RequestBody RequestInfo<FlagRemark> requestInfo){
        FlagRemark remark = requestInfo.getBuss();
        if(StrUtil.hasEmpty(remark.getId())){
            return ResponseInfo.error("标识id参数为空");
        }
        flagRemarkService.deleteFlagRemark(remark.getId());
        return ResponseInfo.success("删除成功");
    }

    /**
     * 查询标识详情
     * @param requestInfo
     * @return
     */
    @PostMapping("/queryRemarkInfo")
    public ResponseInfo queryRemarkInfo(@RequestBody RequestInfo<FlagRemark> requestInfo){
        FlagRemark remark = requestInfo.getBuss();
        if(StrUtil.hasEmpty(remark.getId())){
            return ResponseInfo.error("标识id参数为空");
        }
        return ResponseInfo.success(flagRemarkService.queryInfo(remark.getId()));
    }
}
